<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->

<link href="/Public/Admin/static/h-ui/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="/Public/Admin/static/h-ui.admin/css/H-ui.login.css" rel="stylesheet" type="text/css" />
<link href="/Public/Admin/static/h-ui.admin/css/style.css" rel="stylesheet" type="text/css" />
<link href="/Public/Admin/lib/Hui-iconfont/1.0.8/iconfont.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="/Public/Admin/static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="/Public/Admin/static/h-ui.admin/skin/default/skin.css" id="skin" />

<script type="text/javascript" src="/Public/Admin/lib/jquery/1.9.1/jquery.min.js"></script> 

<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title></title>
<meta name="keywords" content="H-ui.admin v3.1,H-ui网站后台模版,后台模版下载,后台管理系统模版,HTML后台模版下载">
<meta name="description" content="H-ui.admin v3.1，是一款由国人开发的轻量级扁平化网站后台模板，完全免费开源的网站后台管理系统模版，适合中小型CMS后台系统。">
</head>
<body>
	
<link rel="stylesheet" href='/Public/Admin/css/caiDan.css'/>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 微信管理 <span class="c-gray en">&gt;</span> 菜单管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>

<div class="col-lg-6 col-md-6 col-sm-6">
	<div class="phone">
		<div class="phont_foot">
			<div class="caidan" id="caidan">
				<?php if(is_array($caidan)): $i = 0; $__LIST__ = $caidan;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$v): $mod = ($i % 2 );++$i;?><div class='caidan_btn'>
						<button class='btn btn-default' onclick='caidan_btn_click(this,0,"<?php echo U("CaiDan/caidanEdit",array("id"=>$v["id"]));?>")'><?php echo ($v['name']); ?></button>
						
						<div class='sub hidden'>
							<i class='Hui-iconfont'>&#xe6d5;</i>
							<?php if(is_array($v["sub"])): $i = 0; $__LIST__ = $v["sub"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$c): $mod = ($i % 2 );++$i;?><div class='sub_btn'>
									<button class='btn btn-default' onclick='caidan_btn_click(this,1,"<?php echo U("CaiDan/caidanEdit",array("id"=>$c["id"]));?>")'><?php echo ($c['name']); ?></button>
								</div><?php endforeach; endif; else: echo "" ;endif; ?>
							<?php if(count($v['sub'] < 5)): ?><div class='sub_add btn btn-default' onclick='add_sub(this,<?php echo ($v['id']); ?>)'>+</div><?php endif; ?>
						</div>
					</div><?php endforeach; endif; else: echo "" ;endif; ?>
				<?php if(count($caidan) < 3): ?><div onclick="add_caidan(this)" class='caidan_add'>
					<span class="btn btn-default">+</span>
				</div><?php endif; ?>
			</div>
		</div>
	</div>
</div>
<iframe class="content col-lg-5 col-md-5 col-sm-5" src="<?php echo U('CaiDan/caidanEdit');?>" id="content"></iframe>

<button class="btn tongbu btn-primary radius" onclick="tongbu()">同步数据到微信</button>
<script>
	// 同步数据
	function tongbu(){
		var index = layer.load(2,{shade:[0.1,'#333']});
		$.get('<?php echo U("tongbu");?>',function(res){
			layer.close(index);
			if(res == 1){
				layer.msg('同步成功',{icon:6,time:1000});
			}else{
				layer.msg('同步失败，请稍后重试',{icon:5,time:1000});
			}
		});
	}
	$(function(){
		var count = $('#caidan>div').length;
		var width = parseInt($('#caidan').css('width'))/count;
		$('#caidan>div').each(function (){
			$(this).css('width',width+'px');
		});
		
		$('.sub').each(function (){
			var top = parseInt($(this).css('top'));
			var count = $(this).find('.sub_btn').length;
			top = top - count * 50;
			$(this).css('top',top + 'px');
		});
	})
	// 添加一级菜单
	function add_caidan(obj){
		$.post('<?php echo U("CaiDan/addCaiDan");?>',{},function(data){
			if(data.status == 1){
				var count = $('#caidan>div').length;
				var width = parseInt($('#caidan').css('width'));
				var url = data.url;
				var pid = data.pid;
				
				if(count == 1){
					width = width/2;
					addEle(obj,url,pid,width);
				
				}else if(count == 2){
					width = width/3;
					addEle(obj,url,pid,width);
				}else{
					width = width/3;
					addEle(obj,url,pid,width);
					$(obj).hide();
				}
			}else{
				layer.msg('添加菜单失败，请稍后重试',{icon:5,time:1000});
			}
		});
		
	}
	
	function addEle(obj,url,pid,width){
		$("<div class='caidan_btn col-sm-0'><button class='btn btn-default' onclick='caidan_btn_click(this,0,\""+url+"\")'>菜单名称</button><div class='sub hidden'><i class='Hui-iconfont'>&#xe6d5;</i><div class='sub_add btn btn-default' onclick='add_sub(this,"+pid+")'>+</div></div></div>").insertBefore($(obj));
		$('#caidan>div').each(function (){
			$(this).css('width',width+'px');
		});	
	}
	
	// 菜单点击事件
	function caidan_btn_click(obj,type,url){
		$('#caidan').find('.sub').each(function(){
			$(this).addClass('hidden');
		});
		$('#caidan').find('.on').removeClass('on');
		
		if(type == 0){
			$(obj).next().removeClass('hidden');
		}
		$(obj).parents('.sub').removeClass('hidden');
		$(obj).addClass('on');
		
		$('#content').attr('src',url+"?"+Math.random());
	}
	
	// 添加二级菜单
	function add_sub(obj,pid){
		$.post('<?php echo U("CaiDan/addCaiDan");?>',{pid:pid},function(data){
			if(data.status == 1){
				var count = $(obj).parents('.sub').find('.sub_btn').length;
				
				$("<div class='sub_btn'><button class='btn btn-default' onclick='caidan_btn_click(this,1,\""+data.url+"\")'>子菜单</button></div>").insertBefore($(obj));
				var top = parseInt($(obj).parents('.sub').css('top'));
				if(count < 4){
					top = top - 50 + 'px';
					$(obj).parents('.sub').css('top',top);
				}else{
					$(obj).hide();
				}
				
				$(obj).prev('.sub_btn').find('button').click();
			}else{
				layer.msg('添加菜单失败，请稍后重试',{icon:5,time:1000});
			}
		});
	}
</script>


	
<script type="text/javascript" src="/Public/Admin/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="/Public/Admin/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/Public/Admin/static/h-ui.admin/js/H-ui.admin.js"></script> 
<script type="text/javascript" src="/Public/Admin/lib/My97DatePicker/4.8/WdatePicker.js"></script> 
<script type="text/javascript" src="/Public/Admin/lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="/Public/Admin/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="/Public/Admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="/Public/Admin/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="/Public/Admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>

<script type="text/javascript" src="/Public/Admin/lib/webuploader/0.1.5/webuploader.min.js"></script> 
<script type="text/javascript" src="/Public/Admin/lib/ueditor/1.4.3/ueditor.config.js"></script> 
<script type="text/javascript" src="/Public/Admin/lib/ueditor/1.4.3/ueditor.all.min.js"> </script> 
<script type="text/javascript" src="/Public/Admin/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="/Public/Admin/lib/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>
</body>
</html>